#! /usr/bin/env python
# encoding: utf-8
# Thomas Nagy, 2011 (ita)

def options(opt):
	opt.load('compiler_c')

def configure(conf):
	conf.load('compiler_c')

def build(bld):
	bld.program(source='main.c', target='app')

	customize_ze_outputs()

def customize_ze_outputs():
	# first, display strings, people like them
	from waflib import Utils, Logs
	from waflib.Context import Context
	def exec_command(self, cmd, **kw):
		subprocess = Utils.subprocess
		kw['shell'] = isinstance(cmd, str)
		if isinstance(cmd, str):
			Logs.info('%s' % cmd)
		else:
			Logs.info('%s' % ' '.join(cmd)) # here is the change
		Logs.debug('runner_env: kw=%s' % kw)
		try:
			if self.logger:
				self.logger.info(cmd)
				kw['stdout'] = kw['stderr'] = subprocess.PIPE
				p = subprocess.Popen(cmd, **kw)
				(out, err) = p.communicate()
				if out:
					self.logger.debug('out: %s' % out.decode(sys.stdout.encoding or 'iso8859-1'))
				if err:
					self.logger.error('err: %s' % err.decode(sys.stdout.encoding or 'iso8859-1'))
				return p.returncode
			else:
				p = subprocess.Popen(cmd, **kw)
				return p.wait()
		except OSError:
			return -1
	Context.exec_command = exec_command

	# and change the outputs for tasks too
	from waflib.Task import Task
	def display(self):
		return '' # no output on empty strings
	Task.__str__ = display

